#include <bits/stdc++.h>
// 2025/07/10
// tag: Cartesian Tree
// Author: Forever
using namespace std;
using int64 = int64_t;
#define int long long

int n, p[10000001], ls[10000001], rs[10000001];

signed main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> p[i];
    stack<int> st;
    int ans1 = 0, ans2 = 0;
    for (int i = 1; i <= n; i++) {
        int flag = 0;
        while (!st.empty() && p[st.top()] > p[i])
            flag = st.top(), st.pop();
        if (!st.empty())
            rs[st.top()] = i;
        if (flag)
            ls[i] = flag;
        st.push(i);
    }
    for (int i = 1; i <= n; i++)
        ans1 ^= i * (ls[i] + 1), ans2 ^= i * (rs[i] + 1);
    cout << ans1 << " " << ans2;
    return 0;
}